import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { Router, ActivatedRoute } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-pageview',
  templateUrl: './pageview.component.html',
  styleUrls: ['./pageview.component.css']
})
export class PageviewComponent implements OnInit {
  parm:string;
  singlepage:Singlepage;
  constructor(
    private router:Router,
    private routerinfo:ActivatedRoute,
    private singlepageservice:SinglepageService
  ) {
    this.singlepage=new Singlepage();
   }

  ngOnInit() {
    this.parm=this.routerinfo.snapshot.params['id'];
      if(this.parm){
        this.getSinglepage(this.parm);
      }
      else{
        alert("参数异常，请刷新后重试");
        this.goBack();
      }
  }

  goBack(){
    this.router.navigate(['singlepagelist']);
    }

    getSinglepage(id:string){
      this.singlepageservice.getSinglepage(id)
      .then((data:Singlepage)=>{
       if(data){
      this.singlepage=data;
       }
       else{
         alert("通讯异常，请刷新后重试");
       }
      })
    }


}
